<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld"  prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld"  prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>

<%@ page  import="java.util.*" %>
<%@ page  import="com.erp.framework.util.CommonUtil" %>
<%@ page  import="com.erp.app.common.ProjectConstants" %>

<jsp:useBean id="uploadFileForm" scope="session" type="com.erp.common.web.UploadFileForm" />

<%
HashMap params = (HashMap) uploadFileForm.getParams();
%>

<head>
<title>Add Attachment</title>
<link rel="stylesheet" href="<%=request.getContextPath()+ "/css/style.css" %>" type="text/css">

<script language="javascript">
<!--
var isSubmitted = 0;
 
function doSubmit(event) {
    document.forms[0].pageEvent.value = event;
    isSubmitted = 1;
    document.forms[0].submit();
}

function doLoad() {
	<% 
	String lastAction = uploadFileForm.getPageEvent();
	if (!CommonUtil.isEmpty(lastAction) && (lastAction.equals("upload") || lastAction.equals("cancel"))) {
		if (lastAction.equals("upload")) {
			out.println("opener.doSubmit('doNothing');");
		}
		out.println("self.close();");
	}
	%>
	window.moveTo(0, 0);
}
//-->
</script>
</head>
<body onLoad="javascript:doLoad();">

<html:form action="/uploadFile" enctype="multipart/form-data" >
<html:hidden property="pageEvent" />
<html:hidden property="pageMode" />

<table cellpadding=0 cellspacing=0 width=100%>
<% 
    if (params != null) {
        LinkedList keyList = (LinkedList) params.get(ProjectConstants.SESSION_KEY_LIST);
		if (keyList != null) {
			Iterator iterator = keyList.iterator();
			while (iterator.hasNext()) {
				String key = (String) iterator.next();
				String value = (String) iterator.next();
				if (!CommonUtil.isEmpty(key)) {
					out.println("<tr valign=\"top\">");
					out.println("    <td bgcolor=\"#637ACB\" class=\"col_label\">"+key+":</td>");
					out.println("    <td class=\"col_value\">"+value+"</td>");
					out.println("</tr>");
				}
				
			}
		}
    }
%>
<tr valign="top">
     <td class="col_label_upload">&nbsp</td>
     <td class="col_value">
         <html:file property="theFile" />
	 <br>
	 <% if (uploadFileForm.getContent() != null) { %>
	     Uploaded successfully !
	 <% } %>
     </td>
</tr>
<tr valign="top">
    <td class="col_label_upload">&nbsp</td>
    <td class="col_value">
		<input name="btn_upload" type="button" value="Upload" onClick="javascript:doSubmit('upload');" class="button1">
		<input name="btn_cancel" type="button" value="Cancel" onClick="javascript:doSubmit('cancel');" class="button1">
    </td>
</tr>
</table>
</html:form>
</body>